﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ERPStore.Extensions
{
	public static class ExceptionsExtensions
	{
		public static string GetContent(this System.Exception ex)
		{
			var content = new StringBuilder();
			content.Append(ex.StackTrace);
			content.AppendLine();
			content.Append("--------------------------------------------");
			content.AppendLine();
			if (ex.Data != null && ex.Data.Count > 0)
			{
				foreach (object item in ex.Data.Keys)
				{
					if (item != null && ex.Data != null && ex.Data[item] != null)
					{
						content.AppendFormat("{0} = {1}", item, ex.Data[item]);
					}
					content.AppendLine();
				}
			}
			if (ex.InnerException != null)
			{
				content.Append("--------------------------------------------");
				content.AppendLine();
				content.Append("Inner Exception");
				content.AppendLine();
				content.Append(ex.InnerException.GetContent());
			}
			return content.ToString();
		}
	}
}
